package com.ojoin.trade.supplyloan_core.utils.catchdata;

import java.util.concurrent.CountDownLatch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ojoin.trade.common.utils.WaitUtil;
import com.ojoin.trade.supplyloan_core.constdef.IPlatformUrlDef;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;
import com.ojoin.trade.supplyloan_core.web.service.catchdata.ISLDataCatchBaseService;

public class MyCatchDataThread implements Runnable {

	private static final Logger logger = LoggerFactory
			.getLogger(MyCatchDataThread.class);

	private CountDownLatch downLatch;
	private TbSlPlatformUser user;
	private ISLDataCatchBaseService service;
	// 任务编号
    private String jobNum;

	public MyCatchDataThread(CountDownLatch downLatch, TbSlPlatformUser user,
			ISLDataCatchBaseService service,String jobNum) {
		this.downLatch = downLatch;
		this.user = user;
		this.service = service;
		this.jobNum = jobNum;
	}
 
	@Override
	public void run() {
		try {
			logger.info("jobNum-->"+jobNum+"-->platformName->" + user.getPlatformName() + " joinid->"
					+ user.getIdOfTbMerchantUser() + " username->"
					+ user.getUsername() + " 抓取数据开始.");
			
			
			if(user.getEnableFlag().equals(IPlatformUrlDef.Statues.enabled.toString())){
				service.catchData(user);
			}
			
			
			
			WaitUtil.waitTimeSeconds(2);
			
			logger.info("jobNum-->"+jobNum+"-->platformName->" + user.getPlatformName() + " joinid->"
					+ user.getIdOfTbMerchantUser() + " username->"
					+ user.getUsername() + " 抓取数据执行完毕.");
			
			 
		} catch (Exception e) {
			logger.info("jobNum-->"+jobNum+"-->platformName->" + user.getPlatformName() + " joinid->"
					+ user.getIdOfTbMerchantUser() + " username->"
					+ user.getUsername() + " 抓取数据失败.",e);
		} finally {  
			this.downLatch.countDown();
			
		}
	}
	
	public void complted(){
		this.downLatch.countDown();
	}
}
